package com.dk.listenter;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextLoaderListenter implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        ServletContext context = sce.getServletContext();
        String contextConfigLocation = context.getInitParameter("contextConfigLocation");

        ApplicationContext app = new ClassPathXmlApplicationContext(contextConfigLocation);
        //将spring的应用上下问对象存储导ServletContext中

        context.setAttribute("app", app);
        System.out.println("chuangjianwanbi");

    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
